package String;

public class _537_ComplexNumberMultiplication {
    //focus:when a or b=0,
    public String complexNumberMultiply(String a, String b) {
        int apos = a.indexOf("+");
        int bpos = b.indexOf("+");
        int aReal = 0,bReal = 0,aComp = 0,bComp = 0;
        aReal = Integer.parseInt(a.substring(0, apos));
        bReal = Integer.parseInt(b.substring(0, bpos));
        aComp = Integer.parseInt(a.substring(apos + 1, a.length()-1));
        bComp = Integer.parseInt(b.substring(bpos + 1, b.length()-1));
        int real = (aReal*bReal)-(aComp*bComp);
        int comp = (aReal*bComp)+(bReal*aComp);
        return real + "+" + comp + "i";
    }
}
